//
//  PowerRootViewController.m
//  muscleLife
//
//  Created by xalo on 16/5/1.
//  Copyright © 2016年 HeavenAndHell. All rights reserved.
//

#import "PowerRootViewController.h"
#import "PoewerNewsViewController.h"
#import "PowerUsrInfoCell.h"
#import "PowerStartCell.h"

@interface PowerRootViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;//展示页面
@property (retain, nonatomic) HFStretchableTableHeaderView* headerView;//可伸缩的头视图

@end

@implementation PowerRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.bounces = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [self.tableView registerNib:[UINib nibWithNibName:@"PowerUsrInfoCell" bundle:nil] forCellReuseIdentifier:@"PowerUsrInfoCell"];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.tableView registerNib:[UINib nibWithNibName:@"PowerStartCell" bundle:nil] forCellReuseIdentifier:@"PowerStartCell"];
    [self createView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        PowerUsrInfoCell* cell = [tableView dequeueReusableCellWithIdentifier:@"PowerUsrInfoCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }else if (indexPath.row == 1){
        PowerStartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PowerStartCell"];
        
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }

    return nil;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 1) {

        }else{

    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        return 150;
    }
    if (indexPath.row == 1) {
        return 250;
    }
    return 0;
}

-(void)createView{

    //背景
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, kControllerHeight/4)];
    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    bgImageView.clipsToBounds = YES;
    bgImageView.image = [UIImage imageNamed:@"powerNewsImg"];
    //背景之上的内容
    UIView *contentView = [[UIView alloc] initWithFrame:bgImageView.bounds];
    contentView.backgroundColor = [UIColor clearColor];
    [contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    self.headerView = [HFStretchableTableHeaderView new];
    [self.headerView stretchHeaderForTableView:self.tableView withView:bgImageView subViews:contentView];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    [self.headerView scrollViewDidScroll:scrollView];
}

-(void)viewDidLayoutSubviews{

    [self.headerView resizeView];
}

-(void)tapAction:(UITapGestureRecognizer*)sender{
    PoewerNewsViewController* news = [[UIStoryboard storyboardWithName:@"Power" bundle:nil] instantiateViewControllerWithIdentifier:@"PoewerNewsViewController"];
    [self.navigationController pushViewController:news animated:YES];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
